//
//  UIButton+Extension.swift
//  Swift_Weibo
//
//  Created by Tim on 2019/8/13.
//  Copyright © 2019 Tim. All rights reserved.
//  UIButton 扩展

import UIKit

extension UIButton {
    
    /// 快速创建一个图片按钮
    ///
    /// - Parameters:
    ///   - imgName:            图片名称
    ///   - backgroundImgName:  背景图片名称
    /// - Returns:              创建好的按钮
    class func imageBtn(imgName: String, backgroundImgName: String) -> UIButton {
        let btn = UIButton(type: .custom)
        btn.setImage(UIImage(named: imgName), for: .normal)
        btn.setImage(UIImage(named: imgName + "_highlighted"), for: .highlighted)
        btn.setBackgroundImage(UIImage(named: backgroundImgName), for: .normal)
        btn.setBackgroundImage(UIImage(named: backgroundImgName + "_highlighted"), for: .highlighted)
        btn.sizeToFit()
        return btn
    }
    
    class func textBtn(title: String, fontSize: CGFloat = 16.0, normalColor: UIColor, highlightedColor: UIColor, backgroundImg: String?) -> UIButton {
        let btn = UIButton(type: .custom)
        btn.setTitle(title, for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        btn.setTitleColor(normalColor, for: .normal)
        btn.setTitleColor(highlightedColor, for: .highlighted)
        btn.setBackgroundImage(UIImage(named: backgroundImg ?? ""), for: .normal)
        btn.sizeToFit()
        return btn
    }
}
